package com.foreknow.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.foreknow.entity.Fmeditem;
import com.foreknow.entity.User;
import com.foreknow.service.FmeditemService;
import com.foreknow.utils.Constance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/FmeditemController")
public class FmeditemController {

    @Autowired
    private FmeditemService fmeditemService;

    @RequestMapping(value = "/allFmeditem",method = RequestMethod.GET)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    public String allFmeditem() throws JsonProcessingException {

        HashMap<String,Object> hs = new HashMap<>();
        List<Fmeditem>  list = fmeditemService.allFmeditem();
        if (list != null) {
            hs.put("data",list);
            hs.put("meta", new Constance("msg", 200));
        } else {
            hs.put("meta", new Constance("msg", 404));
        }

        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }
}
